<%--
  Created by IntelliJ IDEA.
  User: ZhuChunXiao
  Date: 2017/5/23
  Time: 10:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<style>
  #checkBox{
    height: 50px;
    text-align: center;
    font-size: 12px;
    /*border: 1px solid red;*/
  }
  #checkBox span{
    margin-right: 30px;
  }
  #checkBox input{
    margin-left: 5px;
  }
  .checkText{
    line-height: 50px;
  }
</style>
<div id="page-content">
  <div class="row">

    <div class="col-lg-12">
      <div class="panel">
        <div class="panel-heading">
          <h3 class="panel-title">员工异动总汇</h3>
        </div>
        <div class="panel-body">

          <div id="checkBox">
            <span class="checkText">快速筛选：</span>
            <input type="checkbox" name="changeType" id="choose1Selected" class="magic-checkbox" value="1">
            <label for="choose1Selected">转正申请</label>
            <input type="checkbox" name="changeType" id="choose2Selected" class="magic-checkbox" value="2">
            <label for="choose2Selected">续约申请</label>
            <input type="checkbox" name="changeType" id="choose3Selected" class="magic-checkbox" value="3">
            <label for="choose3Selected">离职申请</label>
            <input type="checkbox" name="changeType" id="choose4Selected" class="magic-checkbox" value="4">
            <label for="choose4Selected">调动申请</label>
          </div>

          <div class="table-responsive">
            <table id="allchange_out_table"></table>
            <div id="allchange_out_page"></div>
          </div>
        </div>
      </div>
    </div>

  </div>
</div>

<script>

  $(function(){

    init_grid_allchange();

  });

  function init_grid_allchange() {

    __init_jqgrid('allchange_out_table', 'allchange_out_page',
            '<%=path%>/com/allChange/list?viewtype=${viewtype}',
            ['用工性质',"变动类型","姓名","年龄","性别","所属部门","岗位","操作","id"],
            [
              {name:'nature',index:'nature',sortable:true,search:true,width:80,searchoptions:{sopt:['cn']}},
              {name:'type',index:'type',sortable:true,search:true,width:100,searchoptions:{sopt:['cn']}},
              {name:'name',index:'name',sortable:true,search:true,width:80,searchoptions:{sopt:['cn']}},
              {name:'age',index:'age',sortable:true,search:true,width:80,searchoptions:{sopt:['cn']}},
              {name:'sex',index:'sex',sortable:true,search:true,width:80,searchoptions:{sopt:['cn']}},
              {name:'department',index:'department',sortable:true,search:true,width:100,searchoptions:{sopt:['cn']}},
              {name:'post',index:'post',sortable:false,search:true,width:100,searchoptions:{sopt:['cn']}},
              {name:'act',index:'act', width:210,sortable:false,search:false,fixed:true,formatter: actFormat},
              {name:'id',index:'id',search:false,hidden:true}
            ],
            true,true
    );

  }

  function useTypeFormat(cellvalue, options, rowObject){
    if(rowObject.nature == 1){
      cellvalue = "正式员工";
    } else if(rowObject.nature == 2){
      cellvalue = "试用员工";
    }else{
      cellvalue = "暂无";
    }
    return cellvalue;
  }

  function typeFormat(cellvalue, options, rowObject){
    if(rowObject.type == "1"){
      cellvalue = "转正申请";
    }else if(rowObject.type == "2"){
      cellvalue = "续约申请";
    }else if(rowObject.type == "3"){
      cellvalue = "离职申请";
    }else if(rowObject.type == "4"){
      cellvalue = "调动申请";
    }else{
      cellvalue = "暂无";
    }
    return cellvalue;
  }

  function actFormat(cellvalue, options, rowObject){
    var id = rowObject.id;
    var toWhere=rowObject.type;
    if(toWhere=="转正申请"){
      cellvalue = '<button class="btn btn-white btn-sm" data-original-title="查看" onclick="fn_formal_read(\'' + id + '\');"><i class="fa fa-eye"> </i> 查看</button> ';
    }else if(toWhere=="续约申请"){
      cellvalue = '<button class="btn btn-white btn-sm" data-original-title="查看" onclick="fn_renewal_read(\'' + id + '\');"><i class="fa fa-eye"> </i> 查看</button> ';
    }else if(toWhere=="离职申请"){
      cellvalue = '<button class="btn btn-white btn-sm" data-original-title="查看" onclick="fn_quit_read(\'' + id + '\');"><i class="fa fa-eye"> </i> 查看</button> ';
    }else if(toWhere=="调动申请"){
      cellvalue = '<button class="btn btn-white btn-sm" data-original-title="查看" onclick="fn_transfer_read(\'' + id + '\');"><i class="fa fa-eye"> </i> 查看</button> ';
    }
    return cellvalue;
  }

  //转正read
  function fn_formal_read(id) {
    loadURL('<%=path%>/com/formal/toRead?allChangeId='+id, $('#page-content'));
  }

  //续约read
  function fn_renewal_read(id) {
    loadURL('<%=path%>/com/renewal/toRead?allChangeId='+id, $('#page-content'));
  }

  //离职read
  function fn_quit_read(id) {
    loadURL('<%=path%>/com/quit/toRead?allChangeId='+id, $('#page-content'));
  }

  //调动read
  function fn_transfer_read(id) {
    loadURL('<%=path%>/com/transfer/toRead?allChangeId='+id, $('#page-content'));
  }

  //快速筛选
  $("input[name='changeType']").click(function(){
    var checkNum=[];
    $("input[name='changeType']:checked").each(function(){
      checkNum.push($(this).val());
    });
    jQuery("#allchange_out_table").jqGrid('setGridParam',{
      datatype:'json',
      url:'<%=path%>/com/allChange/list?checkNum='+checkNum
    }).trigger("reloadGrid");
  });

</script>